package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.SaleRebatesRecordAddDTO;
import org.jsola.hr.dto.SaleRebatesRecordUpdateDTO;
import org.jsola.hr.entity.SaleRebatesRecordDO;
import org.jsola.hr.query.SaleRebatesRecordQuery;
import org.jsola.hr.service.ISaleRebatesRecordService;
import org.jsola.hr.vo.SaleRebatesRecordVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 返费记录
 *
 * @author zhr
 */
@Component
public class SaleRebatesRecordTestHelper extends BaseTestHelper {
    
    @Autowired
    private ISaleRebatesRecordService saleRebatesRecordService;

    /**
     * 生成add测试数据
     * @return SaleRebatesRecordAddDTO
     */
    public SaleRebatesRecordAddDTO getSaleRebatesRecordAddDTO(){
        SaleRebatesRecordAddDTO saleRebatesRecordAddDTO = new SaleRebatesRecordAddDTO();
        saleRebatesRecordAddDTO.setSaleUserId(getRandomValue("varchar",32));
        saleRebatesRecordAddDTO.setSaleName(getRandomValue("varchar",50));
        saleRebatesRecordAddDTO.setCompanyId(getRandomValue("varchar",32));
        saleRebatesRecordAddDTO.setCompanyName(getRandomValue("varchar",50));
        saleRebatesRecordAddDTO.setCalculationMonth(getRandomValue("varchar",50));
        saleRebatesRecordAddDTO.setServerCost(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        saleRebatesRecordAddDTO.setIsNew(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        saleRebatesRecordAddDTO.setRebatesRulesId(getRandomValue("varchar",32));
        saleRebatesRecordAddDTO.setRulesName(getRandomValue("varchar",50));
        saleRebatesRecordAddDTO.setProportion(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        saleRebatesRecordAddDTO.setDividedProportion(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        saleRebatesRecordAddDTO.setRebatesAmount(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        saleRebatesRecordAddDTO.setRemark(getRandomValue("varchar",255));
        return saleRebatesRecordAddDTO;
    }


    /**
     * 生成update测试数据
     * @return SaleRebatesRecordUpdateDTO
     */
    public SaleRebatesRecordUpdateDTO getSaleRebatesRecordUpdateDTO(SaleRebatesRecordVO saleRebatesRecordVO){
        return saleRebatesRecordService.selectDOById(saleRebatesRecordVO.getId(), SITE_ID).to(SaleRebatesRecordUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return SaleRebatesRecordQuery
     */
    public SaleRebatesRecordQuery getSaleRebatesRecordQuery() {
        SaleRebatesRecordQuery saleRebatesRecordQuery = new SaleRebatesRecordQuery();
        List<SaleRebatesRecordDO> saleRebatesRecordDOList = saleRebatesRecordService.list(new SaleRebatesRecordDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(saleRebatesRecordDOList)) {
            SaleRebatesRecordDO saleRebatesRecordDO = saleRebatesRecordDOList.get(0);
            saleRebatesRecordQuery = saleRebatesRecordDO.to(SaleRebatesRecordQuery.class);
        }
        return saleRebatesRecordQuery;
    }

    /**
     * 保存示例
     * @return SaleRebatesRecordVO
     */
    public SaleRebatesRecordVO saveSaleRebatesRecordExample(){
        SaleRebatesRecordAddDTO addDTO = this.getSaleRebatesRecordAddDTO();
        SaleRebatesRecordVO saleRebatesRecordVO = saleRebatesRecordService.save(addDTO,buildTokenUser());
        return saleRebatesRecordVO;
    }


}

